﻿using Company.BLL.WS.GC;
using System.Data;
using System.Data.SqlClient;
using System;
using Company.BLL.Utils;
namespace Company.BLL.GC
{
    public class ThietBi : ThietBiBase
    {
        public static DataSet WS_GetDanhSachDaDangKy(string maHaiQuan, string maDoanhNghiep)
        {
            GCService service = new GCService();
            return service.ThietBi_GetDanhSach(maHaiQuan, maDoanhNghiep);
        }

        public static bool UpdateRegistedToDatabase(string maHaiQuan, string maDoanhNghiep, SqlTransaction transaction)
        {
            // Lấy danh sách từ WEB SERVICE.
            DataSet ds =WS_GetDanhSachDaDangKy(maHaiQuan, maDoanhNghiep);

            // Cập nhật vào CSDL.            
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ThietBi tb = new ThietBi();
                tb.SoHopDong = row["SoHopDong"].ToString();
                tb.MaHaiQuan = maHaiQuan;
                tb.MaDoanhNghiep = maDoanhNghiep;
                tb.NgayKy = Convert.ToDateTime(row["NgayKy"]);
                tb.Ma = row["Ma"].ToString().Substring(1);
                tb.Ten = FontConverter.TCVN2Unicode(row["Ten"].ToString());
                tb.MaHS = row["MaHS"].ToString();
                tb.DVT_ID = row["DVT_ID"].ToString();
                tb.SoLuongDangKy = Convert.ToDecimal(row["SoLuongDangKy"]);
                tb.NuocXX_ID = row["NuocXX_ID"].ToString();
                tb.TinhTrang = row["TinhTrang"].ToString();
                tb.DonGia = Convert.ToDecimal(row["DonGia"].ToString());
                tb.TriGia = Convert.ToDecimal(row["TriGia"].ToString());
                tb.NguyenTe_ID = row["NguyenTe_ID"].ToString();
                tb.InsertUpdateTransaction(transaction);               
            }
            return true;
        }

    }
}